package com.gp.learn.common.core.mybaitsplus;

import com.gp.learn.common.core.mybaitsplus.constants.ErrorCode;

import java.util.HashMap;
import java.util.Map;


public class ResultInfo<T> {

    private Integer code;

    private String messageInfo;

    private T data;

    private Map<String, Object> extraData = new HashMap<>();


    public ResultInfo() {

    }

    public ResultInfo(Integer code, String messageInfo, T data) {
        this.code = code;
        this.messageInfo = messageInfo;
        this.data = data;
    }

    public static ResultInfo error() {
        return new ResultInfo<>().setCode(ErrorCode.FAIL.getCode()).setMessageInfo(ErrorCode.FAIL.getMessage());
    }

    public static ResultInfo error(String messageInfo) {
        return new ResultInfo<>().setCode(ErrorCode.FAIL.getCode()).setMessageInfo(messageInfo);
    }

    public static ResultInfo ok() {
        return new ResultInfo<>().setCode(ErrorCode.OK.getCode()).setMessageInfo(ErrorCode.OK.getMessage());
    }

    public static ResultInfo ok(Object data) {
        return new ResultInfo<>().setCode(ErrorCode.OK.getCode()).setData(data).setMessageInfo(ErrorCode.OK.getMessage());
    }

    public static ResultInfo ok(Object data, Map extraData) {
        return new ResultInfo<>().setCode(ErrorCode.OK.getCode()).setData(data).setExtraData(extraData).setMessageInfo(ErrorCode.OK.getMessage());
    }

    public Integer getCode() {
        return code;
    }

    public ResultInfo setCode(Integer code) {
        this.code = code;
        return this;
    }

    public String getMessageInfo() {
        return messageInfo;
    }

    public ResultInfo setMessageInfo(String messageInfo) {
        this.messageInfo = messageInfo;
        return this;
    }

    public T getData() {
        return data;
    }

    public ResultInfo setData(T data) {
        this.data = data;
        return this;
    }

    public Map<String, Object> getExtraData() {
        return extraData;
    }

    public ResultInfo setExtraData(Map<String, Object> extraData) {
        this.extraData = extraData;
        return this;
    }
}
